package GameLogic
{
	import BasicEngine.Vector2D;
	import DataStore.BmpDataPool;
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.utils.Dictionary;
	import RobotPlayer.BaseRobot;
	import RobotPlayer.RobotFactory;
	public class LargeRadar extends Sprite
	{
		public var Beam:CompleteRadar;
		public var P:Vector2D;
		
		public var shape:Shape;		
		private var center:Point =  new Point(81, 85);
		private var h:int = 70;
		private var bg:Bitmap;
		private var lv:Vector2D; 
		
		private var pointCanvas:Sprite;
		
		public var AvatarPoints:Dictionary;
		
		private var mat:Shape;
		
		public function LargeRadar()
		{
			bg = new Bitmap(BmpDataPool.LuaeditPool[4051]);
			addChild(bg);
			alpha = 0.7;
			Beam = new CompleteRadar(0x00ff00,h,0.1)
			addChild(Beam);
			Beam.x = center.x;
			Beam.y = center.y;
			
			shape = new Shape();
			shape.graphics.beginFill(0xffffff, 1);
			shape.graphics.drawCircle(0, 0, 3);
			addChild(shape);
			
			P =  new Vector2D(1, 1);
			P.Normalize();
			P.Length = 50;
			AvatarPoints = new Dictionary();
			this.addEventListener(Event.ENTER_FRAME, Update);
			
			mat = new Shape();
			mat.graphics.beginFill(0x00ff00, 1);
			mat.graphics.drawCircle(0, 0, 74);
			addChild(mat);
			mat.x = 82;
			mat.y = 85;
			//
			pointCanvas = new Sprite();
			//pointCanvas.addChild(ma);
			addChild(pointCanvas);
			//
			pointCanvas.mask = mat;
		}
		
		public function CreateAvatarPoint(_index:int):void
		{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(0xffffff, 1);
			shape.graphics.drawCircle(0, 0, 3);
			AvatarPoints[_index] = shape;
			pointCanvas.addChild(shape);
		}
		
		public function RemoveAvatarPoint(_index:int):void
		{
			if (AvatarPoints[_index] != null)
			{
			  pointCanvas.removeChild(AvatarPoints[_index]);
			  delete AvatarPoints[_index];
			}
		}
		
		private function Update(e:Event):void
		{
			for each(var item:BaseRobot in RobotFactory.RobotRecords)
			{
				var x:int = item.Pos.X * 0.15;
				var y:int = item.Pos.Y * 0.15;
				AvatarPoints[item.ID].x = x+30;
				AvatarPoints[item.ID].y = y+40;
			}
			
			//shape.x = P.X + center.x ;
			//shape.y = P.Y + center.y;
			//
			//lv = Game.WorldToLocal(P, new Vector2D(center.x,center.y), Beam.Angle);   
			//if( Math.abs(lv.Angle * 180/Math.PI) < 25) 
			//{
				//shape.scaleX = 1.5;
				//shape.scaleY = 1.5;
			//}
			//else
			//{
				//shape.scaleX = 1;
				//shape.scaleY = 1;
			//}
			visible = Game.SetButton.SettingPanel.radar.selected;
		}
	}
}